import { useDict } from '@/utils/dict'
import useCommonStore from '@/store/modules/common'
import { getListByCustomerName } from '@/api/customerManage/customerList'
import { getOrdprojectNoPriv } from '@/api/projectManage/project'
import useUserStore from '@/store/modules/user'
import { treeselect } from '@/api/rsgl/zzjg'
const commonStore = useCommonStore()
const userStore = useUserStore()
/*** 获取字典*/
export const {
  project_phase, //项目阶段
  project_properties, //项目属性
  business_attribute, //业务属性
  project_amount, //项目金额
  bidding_form, //招标形式
  reminder_opening, //开标提醒(提醒时间)
  reminder_method, //提醒方式
  contract_status, //合同状态
  project_status, //项目状态
  process_business_form, //流程业务关联
  followup_method, //跟进方式
  process_approve_status, // 流程审批状态
  bidding_unit //投标单位
} = useDict(
  'project_phase',
  'project_properties',
  'business_attribute',
  'project_amount',
  'bidding_form',
  'reminder_opening',
  'reminder_method',
  'contract_status',
  'project_status',
  'process_business_form',
  'followup_method',
  'process_approve_status',
  'bidding_unit'
)
export const loadingSelect = ref(false) //检索的loading
/***项目列表数据*/
export const projectOptions = ref([])
// /**
//  * 管理项目模糊搜索
//  * @param val 当前输入的值
//  */
// export async function queryProject(val) {
//   if (!val) {
//     return
//   }
//   let params = {
//     pageSize: 10,
//     proName: val
//   }
//   loadingSelect.value = true
//   await getOrdprojectNoPriv(params).then(res => {
//     projectOptions.value = res.rows
//     loadingSelect.value = false
//   })
// }

/***单位公司 数据 start*/
export const companyOptions = ref([])
initFn()
/***所属企业/客户名称数据 start*/
export const parentOptions = ref([]) //所属企业/客户名称数据
/**
 * 所属企业模糊搜索
 * @param val 当前输入的值
 */
export async function queryCustomer(val) {
  if (!val) {
    return
  }
  let params = {
    pageSize: 10,
    customer: val
  }
  loadingSelect.value = true
  let comRes = await getListByCustomerName(params)
  parentOptions.value = comRes.data
  loadingSelect.value = false
}
async function initFn() {
  let orgId = userStore.user['orgId']
  let params = {}
  params.deptId = orgId && orgId == 484 ? 100 : orgId
  let comRes = await treeselect(params)
  companyOptions.value = comRes.code == 200 ? comRes.data : []
}
/***所属企业/客户名称数  end*/
